//
//  settleDeliveryHeaderCell.m
//  ProjectforHDX
//
//  Created by motom on 16/8/8.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "settleDeliveryHeaderCell.h"
@interface settleDeliveryHeaderCell()

@property (nonatomic, strong)SettleDeliveOrder *model;
@property(nonatomic,strong) UIView *headerView;
@property(nonatomic,strong) UIView *cellContentView;

@property(nonatomic,strong) RZCustomLable *labOrderCode;

@property(nonatomic,strong) RZCustomLable *labDate;

@property(nonatomic,strong) RZCustomLable *labTitle;

@property(nonatomic,strong) RZCustomLable *labDatemark;

@property (nonatomic, strong)RZCustomLable  *labNumber;

@property(nonatomic,strong) RZCustomImageView *rightIcon;


@end

@implementation settleDeliveryHeaderCell


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
#define CELL_HEIGHT 130
#define CELL_LABEL_HEIGHT 25
#define CELL_STSTUE_HEIGHT 50
#define CELL_LINE_COLOR [UtilCheck hexStringToColor:@"e1e1df" alpha:1]
- (void)setModel:(SettleDeliveOrder *)model  andBadPlateCount:(NSInteger)badPlateCount andPlateCount:(NSInteger)count {
    if (_model != model) {
        _model=model;
        
        self.cellContentView=[[UIView alloc] init];
        [self.cellContentView setClipsToBounds:YES];
        [self.cellContentView setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
        [self addSubview:self.cellContentView];
        
        self.labOrderCode=[[RZCustomLable alloc] init];
        [self.labOrderCode setFont:CustomFont(12)];
        [self.labOrderCode setTextColor:[UtilCheck hexStringToColor:@"9D9FA1" alpha:1] ];
        [self.cellContentView addSubview:self.labOrderCode];
        
        self.labDate=[[RZCustomLable alloc] init];
        [self.labDate setFont:CustomFont(12)];
        [self.labDate setTextColor:[UtilCheck hexStringToColor:@"9d9fa1" alpha:1] ];
        [self.cellContentView addSubview:self.labDate];
        
        self.labTitle=[[RZCustomLable alloc] init];
        [self.labTitle setFont:CustomFont(14)];
        [self.labTitle setTextColor:[UtilCheck hexStringToColor:@"393939" alpha:1] ];
        [self.cellContentView addSubview:self.labTitle];
        
        self.labDatemark=[[RZCustomLable alloc] init];
        [self.labDatemark setFont:CustomFont(12)];
        [self.labDatemark setTextColor:[UtilCheck hexStringToColor:@"a1a1a1" alpha:1] ];
        [self.cellContentView addSubview:self.labDatemark];
        
        self.rightIcon=[[RZCustomImageView alloc] init];
        [self.rightIcon setImage:BDFILEIMAGENAEM(@"default/iconfont-jinru")];
        [self.cellContentView addSubview:self.rightIcon];
        
        self.labNumber = [[RZCustomLable alloc]init];
        [self.labNumber setFont:CustomFont(13)];
        [self.labNumber setTextColor:[UtilCheck hexStringToColor:@"a1a1a1" alpha:1]];
        [self.cellContentView addSubview:self.labNumber];
        
        
//        NSString *str = [UtilCheck language:@"local.badParts"];
//        NSRange range = [str rangeOfString:@"i"];
//
//        NSAttributedString *number = [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%ld",(long)badPlateCount] attributes:@{NSForegroundColorAttributeName:[UtilCheck hexStringToColor:@"1a57be" alpha:1]}];
//        NSMutableAttributedString *numberTitle = [[NSMutableAttributedString alloc]initWithString:str];
//        [numberTitle replaceCharactersInRange:range withAttributedString:number];
//        self.labNumber.attributedText = numberTitle;
        
        //替代section的view
        CGFloat headerH = 35;
        self.headerView = [[UIView alloc]init];
        [self.headerView setFrame:CGRectMake(0, CELL_HEIGHT-headerH, SCREEN_WIDTH, headerH)];
        self.headerView.backgroundColor = [UIColor colorWithRed:241/255.0 green:246/255.0 blue:250/255.0 alpha:1.0];
        [self.cellContentView addSubview:self.headerView];
        
        //headerview里的控件
        RZCustomLable *messageFrom = [[RZCustomLable alloc]init];
       
        NSMutableAttributedString *meStr = [[NSMutableAttributedString alloc]initWithString:[THMangerTool language:@"Delivery.DeliveryUnit"] attributes:@{NSForegroundColorAttributeName:[UtilCheck hexStringToColor:@"1a57be" alpha:1]}];
    
        NSString *autoStr = [NSString stringWithFormat:@" %@",[THMangerTool language:@"Delivery.Auto"]];
        
        NSAttributedString *backStr = [[NSAttributedString alloc]initWithString:autoStr attributes:@{NSForegroundColorAttributeName:[UtilCheck hexStringToColor:@"9d9fa1" alpha:1] }];
        
        [meStr appendAttributedString:backStr];
        
        messageFrom.attributedText = meStr;
        [self.headerView addSubview:messageFrom ];
        messageFrom.top =10;
        messageFrom.left = 10;
        messageFrom.font = CustomFont(13);
        [messageFrom sizeToFit];
        
        RZCustomLable *messageCount = [[RZCustomLable alloc]init];
        NSString *str2 = [UtilCheck language:@"local.parts"];
        NSRange range2 = [str2 rangeOfString:@"i"];
        NSAttributedString *number2 = [[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%ld",(long)count] attributes:@{NSForegroundColorAttributeName:[UtilCheck hexStringToColor:@"1a57be" alpha:1]}];
        NSMutableAttributedString *numberTitle2 = [[NSMutableAttributedString alloc]initWithString:str2];
        [numberTitle2 replaceCharactersInRange:range2 withAttributedString:number2];

        messageCount.attributedText = numberTitle2;
        messageCount.font = CustomFont(13);
        [self.headerView addSubview:messageCount];
        
        messageCount.top =8;
        [messageCount sizeToFit];
        messageCount.right = SCREEN_WIDTH - 10;
    }
    
    
    [self layoutSubviews];
}



- (void)layoutSubviews {
    
    [self.cellContentView setFrame: CGRectMake(0, 0, SCREEN_WIDTH, CELL_HEIGHT)];
    //订单号
    [self.labOrderCode setFrame:CGRectMake(10, 5, self.cellContentView.width-20, CELL_LABEL_HEIGHT)];
    self.labOrderCode.text=[NSString stringWithFormat:@"%@ :%@",[THMangerTool language:@"main.orderCode"],_model.orderCode];
    self.labOrderCode.numberOfLines=1;
    [self.labOrderCode sizeToFit];
    self.labOrderCode.left=10;
    self.labOrderCode.height=CELL_LABEL_HEIGHT;
    //日期
    [self.labDate setFrame:CGRectMake(SCREEN_WIDTH - 20, 5, self.cellContentView.width-20, CELL_LABEL_HEIGHT)];
    self.labDate.text=_model.orderCreateTime;
    self.labDate.numberOfLines=1;
    [self.labDate sizeToFit];
    self.labDate.left=self.cellContentView.width-self.labDate.width-10;
    self.labDate.height=self.labOrderCode.height;
    
    //线
    [self.cellContentView addSoldLine:1 soldcolor:CELL_LINE_COLOR pointA:CGPointMake(0, self.labOrderCode.bottom+5) pointB:CGPointMake(self.cellContentView.width, self.labOrderCode.bottom+5)];
    
    //姓名  日期
    self.labTitle.text=_model.customer;
    self.labTitle.adjustsFontSizeToFitWidth=NO;
    self.labTitle.numberOfLines=2;
    [self.labTitle sizeToFit];
    self.labTitle.left=10;
    self.labTitle.top = CELL_LABEL_HEIGHT+20;
    
    if(![_model.arriveDate isEqualToString:@""]) {
        NSString *arriveDate = [NSString stringWithFormat:@"%@:%@",[UtilCheck language:@"local.receiveDate"],_model.arriveDate];
        self.labDatemark.text=arriveDate;
        self.labDatemark.numberOfLines=1;
        [self.labDatemark sizeToFit];
        self.labDatemark.left=10;
        self.labDatemark.top= self.labTitle.bottom+5;
    }
  
    
    //故障件
    self.labNumber.numberOfLines = 1;
    self.labNumber.right = SCREEN_WIDTH - 30;
    [self.labNumber sizeToFit];
    self.labNumber.top = self.labTitle.bottom+5;
    
    
    //    //右按钮
    [ self.rightIcon setFrame:CGRectMake(self.cellContentView.width-20,(self.labTitle.bottom+self.labDatemark.top)/2.f-8, 10, 17)];
    self.rightIcon.hidden = YES;
    //线
    [self.cellContentView addSoldLine:1 soldcolor:CELL_LINE_COLOR pointA:CGPointMake(0,CELL_HEIGHT-35) pointB:CGPointMake(self.cellContentView.width, CELL_HEIGHT-35)];
    

    
}

@end
